package com.game.sound
{
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.net.URLRequest;
	
	public class SoundManager
	{
            private var bgSound:Sound =null;
            
            [Embed(mimeType="audio/mpeg",source='assets/effect/sound/blast.mp3')]
            private static const Sound_blast:Class;
     
            [Embed(mimeType="audio/mpeg",source='assets/effect/sound/crash.mp3')]
            private static const Sound_Crash:Class;

            [Embed(mimeType="audio/mpeg",source='assets/effect/sound/go.mp3')]
            private static const Sound_Go:Class;
            
            /*
            [Embed(mimeType="audio/mpeg",source='assets/effect/sound/bg.mp3')]
            private static const Sound_Bg:Class;    
            */        

			public var bgSoundVol:Number=1;
			public var eftSoundVol:Number=1;
			public var bgSoundOn:Boolean=false;
			public var eftSoundOn:Boolean=false;
            private var bgSoundChannel:SoundChannel;		
            private var eftSoundChannel:SoundChannel;	
            
            private var bgTrans:SoundTransform;
            private var eftTrans:SoundTransform;
            private var eftSound_blast:Sound;
            private var eftSound_crash:Sound;
             private var eftSound_go:Sound;
			public function SoundManager()
			{
				eftSound_blast=new Sound_blast as Sound;
				eftSound_crash = new Sound_Crash as Sound;
				
				eftSound_go = new Sound_Go as Sound;
				//bgSound = new Sound_Bg as Sound;
			}

           public function setBGSound(soundOn:Boolean):void{
           	/*
           	  bgSoundOn=soundOn;
           	  if(soundOn){
 				bgSoundChannel = bgSound.play(0,10000);
           	  	setBGSoundVol(this.bgSoundVol);
           	  }else{
				if (bgSoundChannel != null) {
					bgSoundChannel.stop();
				}	
           	  }
           	  */
           }

           public function setBGSoundVol(value:Number):void{
           	 this.bgSoundVol=value;
           	 bgTrans = new  SoundTransform(value);
           	 bgSoundChannel.soundTransform=bgTrans;
           }
           
           public function setEftSound(soundOn:Boolean):void{
           		
           	   this.eftSoundOn=soundOn;
           	   if(this.eftSoundOn){
           	   		setEftSoundVol(this.eftSoundVol);
           	   }else{
 				if (eftSoundChannel != null) {
					eftSoundChannel.stop();
				}	          	   	
           	   }
           }
           public function setEftSoundVol(value:Number):void{
           	 this.eftSoundVol=value;
           	 eftTrans = new  SoundTransform(value);
           	
           } 
           public static var EFT_BLAST:int=0;
           public static var EFT_CRASH:int=1;
           public static var EFT_GO:int=2;
           public function playEftSound(type:int):void{
          
           	if(eftSoundOn){
       		  destroyEft();
              switch(type){
              	case EFT_BLAST:
	           	    eftSoundChannel = eftSound_blast.play(0.5,1,eftTrans);
	           	    break;
              	case EFT_CRASH:
	           	    eftSoundChannel = eftSound_crash.play(0,1,eftTrans);
	           	    break;	   
	           	case EFT_GO:
 					eftSoundChannel = eftSound_go.play(0,1,eftTrans);
	           	    break;	 	           		
	           		            	    
           	  }
           	  //destroyEft();
           	}
           	
           }          
       
           public function destroy():void{
             	if(this.bgSoundChannel)
         			this.bgSoundChannel.stop();
           }


       
           public function destroyEft():void{
             	if(this.eftSoundChannel){
 					this.eftSoundChannel.stop();
             	}
           }
                    	
	}
}